package com.zzz.poker.configuration;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.parameters.Parameter;
import org.springdoc.core.customizers.OperationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    /**
     * 配置基本信息
     *
     * @return
     */
    @Bean
    public OpenAPI cardOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("接口文档")
                        .version("1.0")
                        .description("卡片接口文档")
                        .termsOfService("localhost:8088/users")
                        .contact(new Contact().name("zwq").url("localhost:8088").email("zwq@qq.com"))
                        .license(new License().name("Apache 2.0"))
                )
                .components(new Components()
                        .addParameters("Authorization",
                                new Parameter().in("header").name("Authorization").description("鉴权")
                                        .required(true))

                );
    }


    // 关键：将全局参数注入所有接口
    @Bean
    public OperationCustomizer globalHeaderCustomizer() {
        return (operation, handlerMethod) -> {
            // 引用 Components 定义的参数
            operation.addParametersItem(new Parameter().$ref("#/components/parameters/Authorization").example("1111111111"));
            return operation;
        };
    }

}
